<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="stylesheet" href="<{'static/css/bootstrap/bootstrap.min.css'|url}>" />
		<link rel="stylesheet" href="<{'static/css/bootstrap/bootstrap-responsive.min.css'|url}>" />
		<!--[if lt IE 6]> <link rel="stylesheet" href="<{'static/css/bootstrap/bootstrap-ie6.min.css'|url}>" /> <![endif]-->
		<{include file='html.tpl'}>
		<link rel="stylesheet" href="<{'static/css/unicorn.main.css'|url}>" />
		<link rel="stylesheet" href="<{'static/css/unicorn.grey.css'|url}>" class="skin-color" />

		<{include file="form.tpl"}>

		<script src="<{'static/js/bootstrap/bootstrap.min.js'|url}>"></script>
		<!--[if lt IE 6]> <script src="<{'static/js/bootstrap/bootstrap-ie.js'|url}>"></script> <![endif]-->

	</head>
	<body>
		<div id="header">
			<h1><a href="<{'admin'|url}>">Home</a></h1>	
		</div>
		<{include file="admin/nav.tpl"}>

		<{include file="admin/sidebar.tpl"}>

		<{include file="admin/style-switcher.tpl"}>
		<{$_type_data.boolean='真/假'}>
		<{$_type_data.number='數字'}>
		<{$_type_data.string='文本'}>
		<{$_type_data.text='長文本'}>
		<div id="content">
			<div id="content-header">
				<h1>編輯用戶組字段</h1>
				<{include file="admin/widget.tpl"}>
			</div>
			<div id="breadcrumb">
				<a href="<{'admin'|url}>" title="返回首頁" class="tip-bottom"><i class="icon-home"></i> 後臺</a>
				<a href="<{'admin/group/edit'|url}>">用戶組管理</a>
				<a href="<{'admin/group/edit_fields'|url}>" class="current">編輯用戶組權限字段</a>
			</div>
			<div class="container-fluid">
				<div class="row-fluid">
					<div class="span12">
						<div class="pull-right btn-group">
							<a class="btn btn-small btn-success" href="#new" data-backdrop="static" data-toggle="modal"><i class="icon icon-plus icon-white"></i> 添加權限字段</a>
							<a class="btn btn-small btn-warning" href="<{'admin/group/edit'|url}>"><i class="icon icon-th-list icon-white"></i> 修改用戶組</a>
							<a class="btn btn-small" href="javascript:" onclick="javascript:location.reload();"><i class="icon icon-refresh"></i> 刷新頁面</a>
						</div>
						<div class="clearfix"></div>
						<div class="widget-box">
							<div class="widget-title">
								<span class="icon">
									<i class="icon-align-justify"></i>		
								</span>
								<h5>用戶組權限字段</h5>
							</div>
							<div class="widget-content" >
								<div class="alert alert-block alert-error">
								  <button type="button" class="close" data-dismiss="alert">&times;</button>
									<h4>警告!</h4>
									在操作本頁面之前，請確認您知道您在做什麼！
								</div>
								<table class="table table-striped table-bordered with-check">
									<thead>
										<tr>
											<th>#</th>
											<th>權限名稱(英文)</th>
											<th>介紹</th>
											<th>類型</th>
											<th>父級名稱</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody>
									<{foreach $_fields_data as $key => $item}>
										<tr data-id="<{$item.id|escape}>" data-auth_name="<{$item.auth_name|escape}>" data-text="<{$item.text|escape}>" data-pid="<{$item.pid|escape}>" data-type="<{$item.type|escape}>">
											<td><{$item.id|escape}></td>
											<td><{$item.auth_name|escape}></td>
											<td><{$item.text|escape}></td>
											<td><{$_type_data[$item.type]|escape}></td>
											<td><{$_fields_data[$item.pid].auth_name|escape}></td>
											<td>
												<a href="#update" data-toggle="modal" name="update" class="tip-top" data-original-title="修改" data-backdrop="static" ><i class="icon-pencil"></i></a>
												|
												<a href="<{'admin/group/delete_fields_query'|url}>?id=<{$item.id|escape}>" class="tip-top" confirm="您確定刪除用戶：<{$item.auth_name|escape}>？此操作不可恢復！" name="delete" method="get" data-original-title="刪除權限字段"><i class="icon-trash"></i></a>
											</td>
										</tr>	
									<{/foreach}>
									</tbody>
								</table>
							</div>
						</div>			
					</div>
				</div>
				
				<{include file="admin/copyright.tpl"}>
			</div>
		</div>
		<div id="new" class="modal hide fade">
			<div class="modal-header">
				<button data-dismiss="modal" class="close" type="button">×</button>
				<h3>增加權限字段</h3>
			</div>
			<form action="<{'admin/group/add_fields_query'|url}>" method="POST">
			<div class="modal-body">
				<div class="widget-content nopadding">		
					<div class="control-group">
						<div class="controls">名稱：
							<input type="text" name="auth_name" value="" placeholder="請輸入英文名稱，以[allow_]開始..." /> 
						</div>
						<div class="controls">介紹：
							<input type="text" name="text" value="" placeholder="請輸入漢字介紹..." /> 
						</div>
						<div class="controls">類型：
							<select style="width:80%;" name="type" notheme="notheme">
							<{foreach $_type_data as $key => $item}>
								<option value="<{$key|escape}>"><{$item|escape}></option>
							<{/foreach}>
							</select>
						</div>
						<div class="controls">父級：
							<select style="width:80%;" name="pid" notheme="notheme">
								<option value="0">無父級</option>
								<{foreach $_fields_data as $item}>
								<option value="<{$item.id|escape}>"><{$item.text|escape}>(<{$item.auth_name|escape}>)</option>
								<{/foreach}>
							</select><br />
							在用戶組權限設置中，當父級未設權限時，本項設置的權限無效
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="submit" class="btn btn-primary" href="javascript:">修改</button>
				<a data-dismiss="modal" class="btn" href="#">取消</a>
			</div>
			</form>
		</div>
		<div id="update" class="modal hide fade">
			<div class="modal-header">
				<button data-dismiss="modal" class="close" type="button">×</button>
				<h3>修改權限字段 - <span id="update_auth_name"></span></h3>
			</div>
			<form action="" id="update_form" confirm="您確認修改本權限字段嗎？" method="POST">
			<div class="modal-body">
				<div class="widget-content nopadding">		
					<div class="control-group">
						<div class="controls">名稱：
							<input type="text" name="auth_name" value="" placeholder="請輸入英文名稱，以[allow_]開始..." /> 
						</div>
						<div class="controls">介紹：
							<input type="text" name="text" value="" placeholder="請輸入漢字介紹..." /> 
						</div>
						<div class="controls">類型：
							<select style="width:80%;" name="type" notheme="notheme">
							<{foreach $_type_data as $key => $item}>
								<option value="<{$key|escape}>"><{$item|escape}></option>
							<{/foreach}>
							</select>
						</div>
						<div class="controls">父級：
							<select style="width:80%;" name="pid" notheme="notheme">
								<option value="0">無父級</option>
								<{foreach $_fields_data as $item}>
								<option value="<{$item.id|escape}>"><{$item.text|escape}>(<{$item.auth_name|escape}>)</option>
								<{/foreach}>
							</select><br />
							在用戶組權限設置中，當父級未設權限時，本項設置的權限無效
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="submit" class="btn btn-primary" href="javascript:">修改</button>
				<a data-dismiss="modal" class="btn" href="#">取消</a>
			</div>
			</form>
		</div>
<{include file="admin/footer.tpl"}>
<script type="text/javascript">
(function($){
$().ready(function(){
	$('a[name="update"]').on('click',function(){
		var $tr = $(this).closest("tr");
		var $update_form = $('#update_form').attr('action','<{'admin/group/edit_fields_query'|url}>?id=' + parseInt($tr.data('id')) );
		$('input[name="auth_name"]', $update_form).val($tr.data('auth_name'));
		$('#update_auth_name').text($tr.data('auth_name'));
		$('input[name="text"]', $update_form).val($tr.data('text'));
		$('select[name="type"]', $update_form).val($tr.data('type'));
		var $select = $('select[name="pid"]', $update_form).val(parseInt($tr.data('pid')));
		$('option', $select).prop('disabled',false).filter("[value='"+$tr.data('id')+"']").prop('disabled',true);
	});
	$('form,a[method]').query();
});
})(jQuery);
</script>
	</body>
</html>
